import React from 'react'
import { List, Switch } from 'antd-mobile'
import classNames from 'classnames'
import FormItemHOC from './form-hoc'

const prefixCls = 'zhang-form-switch-item'

class SwitchItem extends React.PureComponent {
  static defaultProps = {
    onChange: () => { },
    value: false,
    disabled: false
  }

  render() {
    const {
      onChange,
      value,
      disabled,
      className,
      ...others
    } = this.props

    const cls = classNames({
      [prefixCls]: true,
      [className]: className
    })

    return (
      <List.Item
        {...others}
        className={cls}
        extra={
          <Switch onChange={onChange} checked={value} disabled={disabled} />
        }
      />
    )
  }
}

export default FormItemHOC(SwitchItem)